package com.contain2.queue;

import java.util.PriorityQueue;

public class PriorityDemo extends PriorityQueue<PriorityDemo.ToDoItem> {

	static class ToDoItem implements Comparable<ToDoItem> {

		private char primary;

		private int secondary;

		private String item;

		public ToDoItem(String td, char pri, int sec) {
			primary = pri;
			secondary = sec;
			item = td;
		}

		@Override
		public int compareTo(ToDoItem o) {
			if (primary > o.primary)
				return 1;
			if (primary == o.primary)
				if (secondary > o.secondary)
					return 1;
				else if (secondary == o.secondary)
					return 0;
			return -1;
		}

		public String toString() {
			return Character.toString(primary) + secondary + ": " + item;
		}

	}

	public void add(String td, char pri, int sec) {
		super.add(new ToDoItem(td, pri, sec));
	}

	public static void main(String[] args) {
		PriorityDemo p = new PriorityDemo();
		p.add("Empty trash", 'C', 4);
		p.add("Feed dog", 'A', 2);
		p.add("Feed bird", 'B', 7);
		p.add("Mow lawn", 'C', 3);
		p.add("Water lawn", 'A', 1);
		p.add("Feed cat", 'B', 1);

		System.out.println(p);
		while (!p.isEmpty()) {
			System.out.println(p.remove());
		}
	}

}
